package com.example.panpan.system.service;

import com.example.common.utils.IMap;
import com.example.panpan.system.mapper.CompanyInfoMapper;
import com.example.panpan.system.model.CompanyInfo;
import com.example.panpan.userManage.mapper.TcUserMapper;
import com.example.panpan.userManage.model.TcUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class PanpanService {
    private static final Logger log = LoggerFactory.getLogger(PanpanService.class);
    @Autowired
    private TcUserMapper tcUserMapper;
    @Autowired
    private CompanyInfoMapper companyInfoMapper;

    public Boolean checkLogin(IMap param){
        String username = param.getString( "username");
        String password = param.getString("password");
        TcUser user = tcUserMapper.selectForLogin(username, null);
        if (null != user) {
            if (!password.equals(user.getPassword())) {
                log.info(user.getUserId() + " password invalid");
                return false;
            } else {
                log.info(user.getUserId() + " login success");
                return true;
            }
        }
        return false;
    }
    public TcUser getLoginUser(IMap param){
        String username = param.getString( "username");
        String password = param.getString("password");
        return tcUserMapper.selectForLogin(username, null);
    }
    public CompanyInfo returnMyCompany(){
        return companyInfoMapper.selectByPrimaryKey("myCompany");
    }
    public int updCompanyInfo(IMap param){
        CompanyInfo companyInfo = companyInfoMapper.selectByPrimaryKey("myCompany");
        companyInfo.setCompanyName(param.getString("companyName"));
        companyInfo.setInfoA(param.getString("infoA"));
        companyInfo.setInfoB(param.getString("infoB"));
        companyInfo.setInfoC(param.getString("infoC"));
        companyInfo.setInfoD(param.getString("infoD"));
        companyInfoMapper.updateByPrimaryKeySelective(companyInfo);
        return 1;
    }
}
